
package com.bstek.urule.model.rete.jsondeserializer;

import com.bstek.urule.model.rete.JsonUtils;
import com.bstek.urule.model.rule.CommonFunctionValue;
import com.bstek.urule.model.rule.Value;
import com.bstek.urule.model.rule.ValueType;
import org.codehaus.jackson.JsonNode;

/**
 * @author Jacky.gao
 * @since 2015年7月30日
 */
public class CommonFunctionValueDeserializer implements ValueDeserializer {
    @Override
    public Value deserialize(JsonNode jsonNode) {
        CommonFunctionValue value = new CommonFunctionValue();
        value.setArithmetic(JsonUtils.parseComplexArithmetic(jsonNode));
        value.setLabel(JsonUtils.getJsonValue(jsonNode, "label"));
        value.setName(JsonUtils.getJsonValue(jsonNode, "name"));
        value.setParameter(JsonUtils.parseCommonFunctionParameter(jsonNode));
        value.setValueType(ValueType.CommonFunction);
        return value;
    }

    @Override
    public boolean support(ValueType type) {
        return type.equals(ValueType.CommonFunction);
    }
}
